import QtQuick 1.0
import "Models/"
import "Delegates/"
import "ListViews/"
import "WebAccess/HttpAccess.js" as WebAccess
import "Util/Util.js" as Util
import "WebAccess/QMLTwitter/"

Rectangle{
    id: _root
//    anchors.fill: parent

    property string title: "Home"
    property int hidePosX: -parent.width

    signal itemClicked(variant mouse)       // リストのアイテムがクリックされた
    signal nextFocusLine(bool increment)    // フォーカスを次へ移動させる
    signal nextFocus(bool increment)        // フォーカスを次のアイテムへ移動させる

    /////////////////////////////////////////////
    //自動更新処理
    Timer {
        interval: _Setting.updateInterval * 1000
        running: true
        repeat: true
        onTriggered: {
//            Util.outputDebugString("Timer: triggered")
            update();
        }
    }

    ////////////////////////////////////////////////activeFocus:
    // キー入力

    // タブキー
    Keys.onTabPressed: {
        if(event.modifiers & Qt.ControlModifier){
            // + ctrl
            nextFocusLine(true);
        }else{
            nextFocus(true);
//            parent.setNextFocus(0, true);
        }

    }
    Keys.onBacktabPressed: {
        if(event.modifiers & Qt.ControlModifier){
            // + ctrl
            nextFocusLine(false);
        }else{
            nextFocus(false);
//            parent.setNextFocus(0, false);
        }
    }

    // キー入力
    Keys.onPressed: {
        var list = null;

        switch(event.key){
        case Qt.Key_Space:
            // ツイートコンテナをとぐる
            //parent.openTweetContainer(!parent.isOpenTweetContainer());
            break;
        case Qt.Key_Escape:
            // ツイートコンテナを閉じる
            parent.openTweetContainer(false);
            break;

        case Qt.Key_F5:
            // 更新
            update();
            break;

        case Qt.Key_Enter:
        case Qt.Key_Return:
            // 選択 or コンテキスト　（ようするにクリック）
            _selectItemInfo.mouse_x = -1;
            _selectItemInfo.mouse_y = -1;
            _selectItemInfo.container = _root;
            list = getActiveListViewObject();
            if(isLeftClickWhenKeyDown()){
                list.clickLeft(list.currentItem);
            }else{
                list.clickRight(list.currentItem);
            }
            break;

        case Qt.Key_Backspace:
        case Qt.Key_Left:
            // ホームへ戻る
            _root.state = "";
            break;

        case Qt.Key_Right:
            // 右へ（ユーザー情報か、タイムライン）
            break;

        case Qt.Key_Down:
            // 下へ
            // イベントこない・・・orz
//            if(event.modifiers & Qt.ControlModifier){
//                // 下へ自分のIDを探索する
//                var list_m = getActiveListViewModel();
//                var list_obj = getActiveListViewObject();
//                if(list_m === null || list_obj === null){
//                }else{
//                    var item = null;
//                    for(var i=list_obj.currentIndex; i<list.count; i++){
//                        item = list.get(i);
//                        if(item.indexOf("@IoriAYANE") >= 0){
//                            list.currentIndex = i;
//                            break;
//                        }
//                    }
//                }
//            }
            break;

        case 16777301:
            // Androidのメニューキー
            if(_menuContainer.state !== "Menu"){
                _menuContainer.open("Menu");
            }else{
                _menuContainer.open("");
            }
            break;

        default:
            break;
        }
        Util.outputDebugString("contents Key=" + event.key + ",text=" + event.text);
    }

    //////////////////////////////////////////////
    //アイテムをクリックしてコンテキストメニュー出したりとかの処理
    function onClickContextItem(type){
//        Util.outputDebugString("onClickContextItem:"
//                               + "type=" + type
//                      + " id=" + _selectItemInfo.itemId
//                      + ",name=" + _selectItemInfo.screenName);

        var is_clear = true;

        switch(type){
        case 0:
            //Mention
            _root.parent.tweet.insertReplyScreenName(_selectItemInfo.screenName, _selectItemInfo.itemId);
            break;
        case 1:
            //Retweet
            is_clear = false;
            _dialogContainer.openMessage("Retweet"
                                         , "Do you do ReTweet of a remark of " + _selectItemInfo.screenName
                                         , _root
                                         , type);
            break;
        case 2:
            //QT
            _root.parent.tweet.setQT(_selectItemInfo.screenName
                                  , _selectItemInfo.itemId
                                  , _selectItemInfo.message);
            break;
        case 3:
            //DM
            _root.parent.tweet.setDM(_selectItemInfo.screenName);
            break;
        case 4:
            //mention all
            _root.parent.tweet.insertReplyScreenNameWithinText(_selectItemInfo.screenName
                                                            , _selectItemInfo.itemId
                                                            , _selectItemInfo.message);
            break;

        case 50:
            //User Info
            _modelUsers.lastSelectScreenName = _selectItemInfo.screenName;
            _modelUsers.lastSelectMessage = _selectItemInfo.message;
            _root.state = "Users";
            break;

        case 51:
            //User Timeline
            _modelUserTimeline.listId = _selectItemInfo.screenName;
            _root.state = "UserTimeline";
            break;

        case 60:
            //in reply to
            _modelInReplyTo.startStatusId = _selectItemInfo.itemId;
            _root.state = "InReplyTo";
            break;

        case 100:
            //Follow
            is_clear = false;
            _dialogContainer.openMessage("Friendship"
                                         , _selectItemInfo.isFollow ?
                                             "Do you remove friendship?"
                                           : "Do you request friendship?"
                                         , _root
                                         , type);
            break;

        case 101:
            //Favorite
            is_clear = false;
            _dialogContainer.openMessage("Favorite"
                                         , _selectItemInfo.isFavorite ?
                                             "Do you remove a favorite?"
                                           : "Do you register a favorite?"
                                         , _root
                                         , type);
            break;

        default:
            break;
        }

        //使ったら消す
        if(is_clear){
            _selectItemInfo.clear();
        }

        return undefined;
    }


    /////////////////////////////////////////////
    // メッセージダイアログからの応答
    signal responseDialogMessage(bool ok, variant param)
    onResponseDialogMessage: {
        switch(param){
        case 1:
            // retweet
            if(!ok){
            }else if(_selectItemInfo.itemId.length === 0){
            }else{
                _twitter.tweets.statusesRetweet(_selectItemInfo.itemId);
            }
            break;

        case 100:
            // follow
            if(!ok){
            }else{
                if(!_selectItemInfo.isFollow){
                    _twitter.friendAndFollowers.friendshipsCreate(_selectItemInfo.screenName);
                }else{
                    _twitter.friendAndFollowers.friendshipsDestory(_selectItemInfo.screenName);
                }
            }

            break;

        case 101:
            // favorites
            if(!ok){
            }else if(!_selectItemInfo.isFavorite){
                // regist
                _twitter.favorites.favoritesCreate(_selectItemInfo.itemId);
            }else{
                // remove
                _twitter.favorites.favoritesDestory(_selectItemInfo.itemId);
            }
            break;
        default:
            break;
        }

        return undefined;
    }


    /////////////////////////////////////////////
    //更新する
    function update(){
        Util.outputDebugString("update : state=" + state);
        var model = getActiveListViewModel();
        if(model === null){
        }else if(model === _modelHome){
        }else{
            model.recent();
        }
    }

    /////////////////////////////////////////////
    // 設定を反映する
    function applySetting(){
        _modelTimeline.countMax = _Setting.viewCountMax;
        _modelMention.countMax = _Setting.viewCountMax;
        _modelDirectMessage.countMax = _Setting.viewCountMax;
        _modelListStatuses.countMax = _Setting.viewCountMax;
        _modelRetweetToMe.countMax = _Setting.viewCountMax;
        _modelRetweetByMe.countMax = _Setting.viewCountMax;
        _modelRetweetOfMe.countMax = _Setting.viewCountMax;
        _modelFavorites.countMax = _Setting.viewCountMax;
        _modelUserTimeline.countMax = _Setting.viewCountMax;
        _modelSearchList.countMax = _Setting.viewCountMax;
        _modelSearch.countMax = _Setting.viewCountMax;

        _modelInReplyTo.inReplyCountMax = _Setting.inReplyCountMax;
    }


    /////////////////////////////////////////////
    // フォーカスを現在アクティブなリストへ持っていく
    function setFocusActiveListView(){
        var list = getActiveListViewObject();
        if(list === null){
        }else{
//            _root.forceActiveFocus();
            list.forceActiveFocus();
            _listObject = list;
        }
    }

    /////////////////////////////////////////////
    // キー入力した時に左クリックを発生させるか
    function isLeftClickWhenKeyDown(){
        var isleft = false;
        switch(state){
        case "":
        case "SearchList":
        case "Retweets":
        case "ListLists":
            isleft = true;
            break;
        default:
            break;
        }
        return isleft;
    }

    /////////////////////////////////////////////
    // 検索のリストビューからモデルのエレメントを取得するためのコールバック
    function getSearchModel(){
        return _modelSearch;
    }
    /////////////////////////////////////////////
    // リストのステータス表示リストビューからモデルのエレメントを取得するためのコールバック
    function getListStatusesModel(){
        return _modelListStatuses;
    }


    /////////////////////////////////////////////
    // 現在表示されているリストビューのモデルを取得する
    function getActiveListViewModel(){
        var model = null;

        switch(state){
        case "Timeline":
            model = _modelTimeline;
            break;
        case "Mention":
            model = _modelMention;
            break;
        case "InReplyTo":
            model = _modelInReplyTo;
            break;
        case "DirectMessage":
            model = _modelDirectMessage;
            break;
        case "ListLists":
            model = _modelListLists;
            break;
        case "ListStatuses":
            model = _modelListStatuses;
            break;
        case "RetweetToMe":
            model = _modelRetweetToMe;
            break;
        case "RetweetByMe":
            model = _modelRetweetByMe;
            break;
        case "RetweetOfMe":
            model = _modelRetweetOfMe;
            break;
        case "Friends":
            model = _modelFriends;
            break;
        case "Followers":
            model = _modelFollowers;
            break;
        case "Favorites":
            model = _modelFavorites;
            break;
        case "Users":
            model = _modelUsers;
            break;
        case "UserTimeline":
            model = _modelUserTimeline;
            break;
        case "SearchList":
            model = _modelSearchList;
            break;
        case "Search":
            model = _modelSearch;
            break;
        default:
            model = _modelHome;
            break;
        }
        return model;
    }

    /////////////////////////////////////////////
    // 現在表示されてるリストビューのオブジェクトを取得する
    function getActiveListViewObject(){
        var list = null;

        switch(state){
        case "Timeline":
            list = _listTimeline;
            break;
        case "Mention":
            list = _listMention;
            break;
        case "InReplyTo":
            list = _listInReplyTo;
            break;
        case "DirectMessage":
            list = _listDirectMessage;
            break;
        case "ListLists":
            list = _listListLists;
            break;
        case "ListStatuses":
            list = _listListStatuses;
            break;
        case "Retweets":
            list = _listRetweets;
            break;
        case "RetweetToMe":
            list = _listRetweetToMe;
            break;
        case "RetweetByMe":
            list = _listRetweetByMe;
            break;
        case "RetweetOfMe":
            list = _listRetweetOfMe;
            break;
        case "Friends":
            list = _listFriends;
            break;
        case "Followers":
            list = _listFollowers;
            break;
        case "Favorites":
            list = _listFavorites;
            break;
        case "Users":
            list = _listUsers;
            break;
        case "UserTimeline":
            list = _listUserTimeline;
            break;
        case "SearchList":
            list = _listSearchList;
            break;
        case "Search":
            list = _listSearch;
            break;
        default:
            list = _listHome;
            break;
        }

        return list;
    }


    property string consumerSecret: ""
    property string consumerKey: ""
    property string oauthToken: ""
    property string oauthTokenSecret: ""
    property string screenName: ""
    property string userId: ""
    QMLTwitter{
        id: _twitter

        consumerKey: _root.consumerKey
        consumerSecret: _root.consumerSecret
        oauthToken: _root.oauthToken
        oauthTokenSecret: _root.oauthTokenSecret
        screenName: _root.screenName
        userId: _root.userId

        // 応答

        // timeline
        onResponseHomeTimeline: {
            _modelTimeline.response(text);
        }
        onResponseMentions: {
            _modelMention.response(text);
        }
//        onResponsePublicTimeline: {
//        }
        onResponseRetweetedByMe: {
            _modelRetweetByMe.response(text);
        }
        onResponseRetweetedToMe: {
            _modelRetweetToMe.response(text);
        }
        onResponseRetweetedOfMe: {
            _modelRetweetOfMe.response(text);;
        }
        onResponseUserTimeline: {
            _modelUserTimeline.response(text);
        }
//        onResponseRetweetedToUser: {
//        }
//        onResponseRetweetedByUser: {
//        }

        // tweets
        onResponseStatusesRetweet: {
            _toast.show("Did Retweet");
            _selectItemInfo.clear();
        }

        // search
        onResponseSearch: {
            _modelSearch.response(text);
        }

        // direct message
        onResponseDirectMessages: {
            _modelDirectMessage.response(text);
        }
        onResponseDirectMessagesSent: {
            _modelDirectMessage.response(text);
        }

        // friends and followers
        onResponseFollowersIds: {
            _modelFollowers.onIdsResponse(text);
        }
        onResponseFriendsIds: {
            _modelFriends.onIdsResponse(text);
        }
        onResponseFriendshipsCreate: {
            _toast.show("Requested friendship.")
        }
        onResponseFriendshipsDestory: {
            _toast.show("Removed frinedship.")
        }

        onResponseFriendshipsLookup: {

        }

        //favorites
        onResponseFavorites: {
            _modelFavorites.response(text);
        }
        onResponseFavoritesCreate: {
            // 登録
            _toast.show("Register a favorite.")
            _selectItemInfo.clear();
        }
        onResponseFavoritesDestory: {
            // 解除
            _toast.show("Removed a favorite.")
            _selectItemInfo.clear();
        }

        //lists
        onResponseListsStatuses: {
            _modelListStatuses.response(text);
        }
        onResponseLists: {
            _modelListLists.response(text);
        }
        onResponseListsSubscriptions: {
            _modelListLists.response(text);
        }

        // Search
        onResponseSavedSearhes: {
            _modelSearchList.response(text);
        }
    }


    ////////////////////////////////////
    // ハイライト用
    property variant _listObject: _listHome
    Component {
        id: _highlightBar
        Rectangle {
            width: (_listObject.currentItem === null) ? 0 : _listObject.currentItem.width
            height: (_listObject.currentItem === null) ? 0 : _listObject.currentItem.height
            color: _Setting.itemBkColorSelected
//            radius: 20
            y: (_listObject.currentItem === null) ? 0 : _listObject.currentItem.y;
            Behavior on y { SmoothedAnimation { duration: 200 } }
//            Behavior on y { SpringAnimation { spring: 2; damping: 0.1 } }
        }
    }


    ////////////////////////////////////
    //Timeline
    ListViewTimeline {
        id: _listTimeline
        x: hidePosX
        opacity: 0
        // ハイライト設定
        highlight: _highlightBar
        highlightFollowsCurrentItem: false

        oauthScreenName: _twitter.screenName

        onItemClicked: {
            _root.itemClicked(mouse);
        }

        //ヘッダー
        header: ListViewFooter {
            text: "Recent..."
            loading: !_modelTimeline.isReady
            onClicked: {
                _modelTimeline.recent();
            }
        }

        //フッター
        footer: ListViewFooter {
            text: "More..."
            loading: !_modelTimeline.isReady
            onClicked: {
                _modelTimeline.more();
            }
        }

        //モデル
        model: ModelTimeline{
            id: _modelTimeline
            sourceType: 0
            objTwitter: _twitter
            updateCount: _Setting.updateCount
        }
    }


    ////////////////////////////////////
    //Mention
    ListViewTimeline {
        id: _listMention
        x: hidePosX
        opacity: 0
        // ハイライト設定
        highlight: _highlightBar
        highlightFollowsCurrentItem: false

        oauthScreenName: _twitter.screenName

        onItemClicked: {
            _root.itemClicked(mouse);
        }

        //ヘッダー
        header: ListViewFooter {
            text: "Recent..."
            loading: !_modelMention.isReady
            onClicked: {
                _modelMention.recent();
            }
        }

        //フッター
        footer: ListViewFooter {
            text: "More..."
            loading: !_modelMention.isReady
            onClicked: {
                _modelMention.more();
            }
        }

        //モデル
        model: ModelTimeline{
            id: _modelMention
            sourceType: 1
            objTwitter: _twitter
            updateCount: _Setting.updateCount
        }
    }


    ////////////////////////////////////
    //in reply to
    ListViewTimeline {
        id: _listInReplyTo
        x: hidePosX
        opacity: 0
        // ハイライト設定
        highlight: _highlightBar
        highlightFollowsCurrentItem: false
        // user info
        oauthScreenName: _twitter.screenName

        onItemClicked: {
            _root.itemClicked(mouse);
        }

        //フッター
        footer: ListViewFooter {
            text: "More..."
            loading: !_modelInReplyTo.isReady
            visible: _modelInReplyTo.hasMoreItem
            onClicked: {
                _modelInReplyTo.more();
            }
        }

        //モデル
        model: ModelInReplyTo{
            id: _modelInReplyTo
            objTwitter: _twitter
            inReplyCountMax: _Setting.inReplyCountMax
//            startStatusId: _selectItemInfo.itemId
        }
    }


    ////////////////////////////////////
    //DM
    ListViewTimeline {
        id: _listDirectMessage
        x: hidePosX
        opacity: 0
        // ハイライト設定
        highlight: _highlightBar
        highlightFollowsCurrentItem: false
        // user info
        oauthScreenName: _twitter.screenName

        onItemClicked: {
            _root.itemClicked(mouse);
        }

        //ヘッダー
        header: ListViewFooter {
            text: "Recent..."
            loading: !_modelDirectMessage.isReady
            onClicked: {
                _modelDirectMessage.recent();
            }
        }

        //フッター
        footer: ListViewFooter {
            text: "More..."
            loading: !_modelDirectMessage.isReady
            onClicked: {
                _modelDirectMessage.more();
            }
        }

        //モデル
        model: ModelTimeline{
            id: _modelDirectMessage
            sourceType: 2
            objTwitter: _twitter
            updateCount: _Setting.updateCount
        }
    }



    ////////////////////////////////////
    //List Lists
    ListViewListLists {
        id: _listListLists
        x: hidePosX
        opacity: 0
        // ハイライト設定
        highlight: _highlightBar
        highlightFollowsCurrentItem: false

        onItemClicked: {
            _root.itemClicked(mouse);
        }

        //モデル
        model: ModelListLists{
            id: _modelListLists
            objTwitter: _twitter
        }
    }

    ////////////////////////////////////
    //List statuses
    ListViewTimeline {
        id: _listListStatuses
        x: hidePosX
        opacity: 0
        // ハイライト設定
        highlight: _highlightBar
        highlightFollowsCurrentItem: false
        // user info
        oauthScreenName: _twitter.screenName

        onItemClicked: {
            _root.itemClicked(mouse);
        }

        //ヘッダー
        header: ListViewFooter {
            text: "Recent..."
            loading: !_modelListStatuses.isReady
            onClicked: {
                _modelListStatuses.recent();
            }
        }

        //フッター
        footer: ListViewFooter {
            text: "More..."
            loading: !_modelListStatuses.isReady
            onClicked: {
                _modelListStatuses.more();
            }
        }

        //モデル
        model: ModelTimeline{
            id: _modelListStatuses
//            listId: _selectItemInfo.listId
            sourceType: 4
            objTwitter: _twitter
            updateCount: _Setting.updateCount
        }
    }

    ////////////////////////////////////
    //Retweets
    ListViewRetweets {
        id: _listRetweets
        x: hidePosX
        opacity: 0
        // ハイライト設定
        highlight: _highlightBar
        highlightFollowsCurrentItem: false

        onItemClicked: {
            _root.itemClicked(mouse);
        }

        model: ModelRetweets{
        }
    }



    ////////////////////////////////////
    //Retweet To me
    ListViewTimeline {
        id: _listRetweetToMe
        x: hidePosX
        opacity: 0
        // ハイライト設定
        highlight: _highlightBar
        highlightFollowsCurrentItem: false
        // user info
        oauthScreenName: _twitter.screenName

        onItemClicked: {
            _root.itemClicked(mouse);
        }

        //ヘッダー
        header: ListViewFooter {
            text: "Recent..."
            loading: !_modelRetweetToMe.isReady
            onClicked: {
                _modelRetweetToMe.recent();
            }
        }

        //フッター
        footer: ListViewFooter {
            text: "More..."
            loading: !_modelRetweetToMe.isReady
            onClicked: {
                _modelRetweetToMe.more();
            }
        }

        //モデル
        model: ModelTimeline{
            id: _modelRetweetToMe
            sourceType: 7
            objTwitter: _twitter
            updateCount: _Setting.updateCount
        }
    }

    ////////////////////////////////////
    //Retweet by me
    ListViewTimeline {
        id: _listRetweetByMe
        x: hidePosX
        opacity: 0
        // ハイライト設定
        highlight: _highlightBar
        highlightFollowsCurrentItem: false
        // user info
        oauthScreenName: _twitter.screenName

        onItemClicked: {
            _root.itemClicked(mouse);
        }

        //ヘッダー
        header: ListViewFooter {
            text: "Recent..."
            loading: !_modelRetweetByMe.isReady
            onClicked: {
                _modelRetweetByMe.recent();
            }
        }

        //フッター
        footer: ListViewFooter {
            text: "More..."
            loading: !_modelRetweetByMe.isReady
            onClicked: {
                _modelRetweetByMe.more();
            }
        }

        //モデル
        model: ModelTimeline{
            id: _modelRetweetByMe
            sourceType: 8
            objTwitter: _twitter
            updateCount: _Setting.updateCount
        }
    }

    ////////////////////////////////////
    //Retweet of me
    ListViewTimeline {
        id: _listRetweetOfMe
        x: hidePosX
        opacity: 0
        // ハイライト設定
        highlight: _highlightBar
        highlightFollowsCurrentItem: false
        // user info
        oauthScreenName: _twitter.screenName

        onItemClicked: {
            _root.itemClicked(mouse);
        }

        //ヘッダー
        header: ListViewFooter {
            text: "Recent..."
            loading: !_modelRetweetOfMe.isReady
            onClicked: {
                _modelRetweetOfMe.recent();
            }
        }

        //フッター
        footer: ListViewFooter {
            text: "More..."
            loading: !_modelRetweetOfMe.isReady
            onClicked: {
                _modelRetweetOfMe.more();
            }
        }

        //モデル
        model: ModelTimeline{
            id: _modelRetweetOfMe
            sourceType: 9
            objTwitter: _twitter
            updateCount: _Setting.updateCount
        }
    }


    ////////////////////////////////////
    //Friends
    ListViewUsers {
        id: _listFriends
        x: hidePosX
        opacity: 0
        // ハイライト設定
        highlight: _highlightBar
        highlightFollowsCurrentItem: false

        onItemClicked: {
            _root.itemClicked(mouse);
        }

        //モデル
        model: ModelFriendsFollowers{
            id: _modelFriends
            sourceType: 0
            objTwitter: _twitter
        }
    }

    ////////////////////////////////////
    //Followers
    ListViewUsers {
        id: _listFollowers
        x: hidePosX
        opacity: 0
        // ハイライト設定
        highlight: _highlightBar
        highlightFollowsCurrentItem: false

        onItemClicked: {
            _root.itemClicked(mouse);
        }

        //モデル
        model: ModelFriendsFollowers{
            id: _modelFollowers
            sourceType: 1
            objTwitter: _twitter
        }
    }

    ////////////////////////////////////
    //Favorites
    ListViewTimeline {
        id: _listFavorites
        x: hidePosX
        opacity: 0
        // ハイライト設定
        highlight: _highlightBar
        highlightFollowsCurrentItem: false
        // user info
        oauthScreenName: _twitter.screenName

        onItemClicked: {
            _root.itemClicked(mouse);
        }

        //ヘッダー
        header: ListViewFooter {
            text: "Recent..."
            loading: !_modelFavorites.isReady
            onClicked: {
                _modelFavorites.recent();
            }
        }

        //フッター
        footer: ListViewFooter {
            text: "More..."
            loading: !_modelFavorites.isReady
            onClicked: {
                _modelFavorites.more();
            }
        }

        //モデル
        model: ModelTimeline{
            id: _modelFavorites
            sourceType: 10
            objTwitter: _twitter
            updateCount: _Setting.updateCount
        }
    }


    ////////////////////////////////////
    // Users
    ListViewUsers {
        id: _listUsers
        x: hidePosX
        opacity: 0
        // ハイライト設定
        highlight: _highlightBar
        highlightFollowsCurrentItem: false

        onItemClicked: {
            _root.itemClicked(mouse);
        }

        //モデル
        model: ModelFriendsFollowers{
            id: _modelUsers
//            lastSelectScreenName: _selectItemInfo.screenName
//            lastSelectMessage: _selectItemInfo.message
            sourceType: 2
            objTwitter: _twitter
        }
    }

    ////////////////////////////////////
    //UserTImeline
    ListViewTimeline {
        id: _listUserTimeline
        x: hidePosX
        opacity: 0
        // ハイライト設定
        highlight: _highlightBar
        highlightFollowsCurrentItem: false
        // user info
        oauthScreenName: _twitter.screenName

        onItemClicked: {
            _root.itemClicked(mouse);
        }

        //ヘッダー
        header: ListViewFooter {
            text: "Recent..."
            loading: !_modelUserTimeline.isReady
            onClicked: {
                _modelUserTimeline.recent();
            }
        }

        //フッター
        footer: ListViewFooter {
            text: "More..."
            loading: !_modelUserTimeline.isReady
            onClicked: {
                _modelUserTimeline.more();
            }
        }

        //モデル
        model: ModelTimeline{
            id: _modelUserTimeline
//            listId: _selectItemInfo.screenName
            sourceType: 11
            objTwitter: _twitter
            updateCount: _Setting.updateCount
        }
    }

    ////////////////////////////////////
    //SearchList
    ListViewSearchList {
        id: _listSearchList
        x: hidePosX
        opacity: 0
        // ハイライト設定
        highlight: _highlightBar
        highlightFollowsCurrentItem: false

        onItemClicked: {
            _root.itemClicked(mouse);
        }

        model: ModelSearchList{
            id: _modelSearchList
            objTwitter: _twitter
        }
    }

    ////////////////////////////////////
    //Search
    ListViewSearch {
        id: _listSearch
        x: hidePosX
        opacity: 0
        // ハイライト設定
        highlight: _highlightBar
        highlightFollowsCurrentItem: false

        onItemClicked: {
            _root.itemClicked(mouse);
        }

        //ヘッダー
        header: ListViewFooter {
            text: "Recent..."
            loading: !_modelSearch.isReady
            onClicked: {
                _modelSearch.recent();
            }
        }

        //フッター
//        footer: ListViewFooter {
//            text: "More..."
//            loading: !_modelSearch.isReady
//            onClicked: {
//                _modelSearch.more();
//            }
//        }

        model: ModelSearch{
            id: _modelSearch
            objTwitter: _twitter
        }
    }

    ////////////////////////////////////
    //Home
    ListViewHome {
        id: _listHome
        x: 0
        // ハイライト設定
        highlight: _highlightBar
        highlightFollowsCurrentItem: false

        onItemClicked: {
            _root.itemClicked(mouse);
        }

        model: ModelHome{
            id: _modelHome
        }
    }



    ////////////////////////////////////
    //本文の表示エリアの状態
    states: [
        State {
            name: "Timeline"
            //位置変更
            PropertyChanges{
                target: _listHome
                x: hidePosX
                opacity: 0
            }
            PropertyChanges{
                target: _listTimeline
                x: 0
                opacity: 1.0
            }
            //タイトル表示変更
            PropertyChanges {
                target: _root
                title: "Timeline"
            }
        },
        State {
            name: "Mention"
            //位置変更
            PropertyChanges{
                target: _listHome
                x: hidePosX
                opacity: 0
            }
            PropertyChanges{
                target: _listMention
                x: 0
                opacity: 1.0
            }
            //タイトル表示変更
            PropertyChanges {
                target: _root
                title: "Mention"
            }
        },
        State {
            name: "InReplyTo"
            //位置変更
            PropertyChanges{
                target: _listHome
                x: hidePosX
                opacity: 0
            }
            PropertyChanges{
                target: _listInReplyTo
                x: 0
                opacity: 1.0
            }
            //タイトル表示変更
            PropertyChanges {
                target: _root
                title: "In reply to"
            }
        },
        State {
            name: "DirectMessage"
            //位置変更
            PropertyChanges{
                target: _listHome
                x: hidePosX
                opacity: 0
            }
            PropertyChanges {
                target: _listDirectMessage
                x: 0
                opacity: 1.0
            }
            //タイトル表示変更
            PropertyChanges {
                target: _root
                title: "DM"
            }
        },
        State {
            name: "ListLists"
            //位置変更
            PropertyChanges{
                target: _listHome
                x: hidePosX
                opacity: 0
            }
            PropertyChanges {
                target: _listListLists
                x: 0
                opacity: 1.0
            }
            //タイトル表示変更
            PropertyChanges {
                target: _root
                title: "Lists"
            }
        },
        State {
            name: "ListStatuses"
            //位置変更
            PropertyChanges{
                target: _listHome
                x: hidePosX
                opacity: 0
            }
            PropertyChanges {
                target: _listListStatuses
                x: 0
                opacity: 1.0
            }
            //タイトル表示変更ListStatuses
            PropertyChanges {
                target: _root
                title: _selectItemInfo.listName
            }
        },
        State {
            name: "Retweets"
            //位置変更
            PropertyChanges{
                target: _listHome
                x: hidePosX
                opacity: 0
            }
            PropertyChanges {
                target: _listRetweets
                x: 0
                opacity: 1.0
            }
            //タイトル表示変更
            PropertyChanges {
                target: _root
                title: "Retweets"
            }
        },
        State {
            name: "RetweetToMe"
            //位置変更
            PropertyChanges{
                target: _listHome
                x: hidePosX
                opacity: 0
            }
            PropertyChanges {
                target: _listRetweetToMe
                x: 0
                opacity: 1.0
            }
            //タイトル表示変更
            PropertyChanges {
                target: _root
                title: "Retweets by others"
            }
        },
        State {
            name: "RetweetByMe"
            //位置変更
            PropertyChanges{
                target: _listHome
                x: hidePosX
                opacity: 0
            }
            PropertyChanges {
                target: _listRetweetByMe
                x: 0
                opacity: 1.0
            }
            //タイトル表示変更
            PropertyChanges {
                target: _root
                title: "Retweets by you"
            }
        },
        State {
            name: "RetweetOfMe"
            //位置変更
            PropertyChanges{
                target: _listHome
                x: hidePosX
                opacity: 0
            }
            PropertyChanges {
                target: _listRetweetOfMe
                x: 0
                opacity: 1.0
            }
            //タイトル表示変更
            PropertyChanges {
                target: _root
                title: "Retweets of you"
            }
        },
        State {
            name: "Friends"
            //位置変更
            PropertyChanges{
                target: _listHome
                x: hidePosX
                opacity: 0
            }
            PropertyChanges {
                target: _listFriends
                x: 0
                opacity: 1.0
            }
            //タイトル表示変更
            PropertyChanges {
                target: _root
                title: "Friends"
            }
        },
        State {
            name: "Followers"
            //位置変更
            PropertyChanges{
                target: _listHome
                x: hidePosX
                opacity: 0
            }
            PropertyChanges {
                target: _listFollowers
                x: 0
                opacity: 1.0
            }
            //タイトル表示変更
            PropertyChanges {
                target: _root
                title: "Followers"
            }
        },
        State {
            name: "Favorites"
            //位置変更
            PropertyChanges{
                target: _listHome
                x: hidePosX
                opacity: 0
            }
            PropertyChanges{
                target: _listFavorites
                x: 0
                opacity: 1.0
            }
            //タイトル表示変更
            PropertyChanges {
                target: _root
                title: "Favorites"
            }
        },
        State {
            name: "Users"
            //位置変更
            PropertyChanges{
                target: _listHome
                x: hidePosX
                opacity: 0
            }
            PropertyChanges{
                target: _listUsers
                x: 0
                opacity: 1.0
            }
            //タイトル表示変更
            PropertyChanges {
                target: _root
                title: "Users"
            }
        },
        State {
            name: "UserTimeline"
            //位置変更
            PropertyChanges{
                target: _listHome
                x: hidePosX
                opacity: 0
            }
            PropertyChanges{
                target: _listUserTimeline
                x: 0
                opacity: 1.0
            }
            //タイトル表示変更
            PropertyChanges {
                target: _root
                title: "UserTimeline"
            }
        },
        State {
            name: "SearchList"
            //位置変更
            PropertyChanges{
                target: _listHome
                x: hidePosX
                opacity: 0
            }
            PropertyChanges{
                target: _listSearchList
                x: 0
                opacity: 1.0
            }
            //タイトル表示変更
            PropertyChanges {
                target: _root
                title: "SearchList"
            }
        },
        State {
            name: "Search"
            //位置変更
            PropertyChanges{
                target: _listHome
                x: hidePosX
                opacity: 0
            }
            PropertyChanges{
                target: _listSearch
                x: 0
                opacity: 1.0
            }
            //タイトル表示変更
            PropertyChanges {
                target: _root
                title: "Search"
            }
        }

    ]

    //本文の表示エリアのアニメーション
    transitions:
        Transition {
            SequentialAnimation {
//                NumberAnimation {
//                    easing.type: Easing.OutCubic
//                    target: _listHome
//                    properties: "x"
//                    duration: 500
//                }
                ScriptAction {
                    script: {
                        update();
                        setFocusActiveListView();
                    }
                }
                NumberAnimation {
                    easing.type: Easing.OutCubic
                    targets: [_listHome
                            , _listTimeline, _listMention, _listInReplyTo, _listDirectMessage
                            , _listListLists, _listListStatuses
                            , _listRetweets, _listRetweetToMe, _listRetweetByMe, _listRetweetOfMe
                            , _listFriends, _listFollowers, _listFavorites
                            , _listUsers, _listUserTimeline
                            , _listSearchList, _listSearch]
                    property: "x"
                    duration: 500
                }
            }
        }

}
